package foodunion;

import java.util.Scanner;

/**
 * @author 10070
 */
public class FoodUnion {
    /**
     * 吃货联盟订餐系统
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        /*
         * 各种订单信息分数组
         */
        String[] food = new String[4];
        food[0] = "红烧带鱼";
        food[1] = "鱼香肉丝";
        food[2] = "辣炒鱿鱼";
        food[3] = "时令素菜";
        //菜品名字

        double[] foodPrice = new double[4];
        foodPrice[0] = 38.0;
        foodPrice[1] = 20.0;
        foodPrice[2] = 46.0;
        foodPrice[3] = 10.0;
        //菜品价格

        int[] like = new int[4];
        //菜品点赞数

        String[] name = new String[4];
        //订单人姓名

        String[] foodName = new String[4];
        //菜品

        int[] foodQuantity = new int[4];
        //购买菜品数量

        String[] time = new String[4];
        //订单时间时间

        String[] address = new String[4];
        //订单地址

        double[] foodSum = new double[4];
        //订单总金额

        int[] condition = new int[4];
        //订单状态、0是已预订、1是已完成、2是待定

        int nameId = 0;
        //第几位顾客


        /**添加顾客*/
        name[0] = "张三";
        foodName[0] ="鱼香肉丝" ;
        foodQuantity[0] = 2;
        time[0] = "12:00";
        address[0] = "爱心公寓302";
        foodSum[0] = 40;
        condition[0] = 0;

        name[1] = "李四";
        foodName[1] ="红烧带鱼" ;
        foodQuantity[1] = 1;
        time[1] = "12:30";
        address[1] = "破锣村182号";
        foodSum[1] = 38;
        condition[1] = 1;

        name[2] = "王五";
        foodName[2] ="时令素菜" ;
        foodQuantity[2] = 3;
        time[2] = "14:20";
        address[2] = "一个神秘的地点";
        foodSum[2] = 30;
        condition[2] = 0;

        for (int i = 0; i < 9999;) {
            /*
             * 总体六点
             * 1、我要订餐 2、查看餐袋 3、签收订单 4、删除订单 5、我要点赞 6、退出系统
             */
            System.out.println("欢迎使用吃货联盟");
            System.out.println("*****************************************************************************");
            System.out.println("1、我要订餐");
            System.out.println("2、查看餐袋");
            System.out.println("3、签收订单");
            System.out.println("4、删除订单");
            System.out.println("5、我要点赞");
            System.out.println("6、退出系统");
            System.out.println("*****************************************************************************");
            System.out.println("请选择：");
            int number = input.nextInt();
            for (int j = 0; j < name.length; j++) {
                if(name[j] == null){
                        nameId = j;

                }
            }
            //第几位顾客
            if (number > 0 && number < 6) {
                switch (number) {
                    /*
                     * 我要订餐
                     */
                    case 1:
                        System.out.println("我要订餐");
                        System.out.println("*****************************************************************************");
                        System.out.println("菜品编码\t菜品名称\t单价\t\t点赞数");
                        for (int j = 0; j < 4; j++) {
                            System.out.println((j + 1) + "\t\t" + food[j] + "\t" + foodPrice[j] + "\t  " + like[j]);
                        }
                        System.out.println("请输入您的名字");
                        name[nameId] = input.next();
                        System.out.println("请输入您的需要的菜品编码");
                        int foodNumber = (input.nextInt() - 1);
                        foodName[nameId] = food[foodNumber];
                        System.out.println("请输入您需要的数量");
                        foodQuantity[nameId] = input.nextInt();
                        System.out.println("请输入送餐时间（如14:30）");
                        time[nameId] = input.next();
                        System.out.println("请输入送地址");
                        address[nameId] = input.next();
                        foodSum[nameId] = (foodPrice[foodNumber]) * (foodQuantity[nameId]);
                        System.out.println("您的订单为：\n" + name[nameId] + "\t" + food[foodNumber] + "\t" + foodQuantity[nameId] + "份\n" + address[nameId] + "\n" + "总金额为：" + foodSum[nameId]);
                            condition[nameId] = 0;
                        System.out.println("下单成功");
                        System.out.println("输入0返回上一菜单");
                        int numberNo = input.nextInt();
                        if(numberNo != 999999999){
                            break;
                        }
                    /*
                     * 查看餐袋
                     */
                    case 2:
                        System.out.println("查看餐袋");
                        System.out.println("*****************************************************************************");
                        System.out.println("订单编号|订餐人|所定餐及份数|时间|送餐地址|价格|状态（0是已预订、1是已完成）");
                        for (int j = 0; j < name.length; j++) {
                            if(name[j] != null){
                            System.out.print((j + 1) + " | " + name[j] );
                            System.out.print(" | "+ foodName[j] + "  " + foodQuantity[j] +"份"+ " | ");
                            System.out.print(time[j] + " | " + address[j] + " | " );
                            System.out.println(foodSum[j] + " | " + condition[j]);
                            }
                        }
                        System.out.println("输入0返回上一菜单");
                        numberNo = input.nextInt();
                        if(numberNo != 999999999){
                            break;
                        }
                        break;
                    case 3:
                        System.out.println("签收订单");
                        System.out.println("*****************************************************************************");
                        System.out.println("请问你要签收那份订单：");
                        int signForReceipt = input.nextInt();
                        switch (signForReceipt) {
                            case 1:
                                condition[0] = 1;
                                break;
                            case 2:
                                condition[1] = 1;
                                break;
                            case 3:
                                condition[2] = 1;
                                break;
                            case 4:
                                condition[3] = 1;
                                break;
                            default:
                                System.out.println("输入错误");
                                break;
                        }

                        System.out.println("输入0返回上一菜单");
                        numberNo = input.nextInt();
                        if(numberNo != 999999999){
                            break;
                        }
                    case 4:
                        System.out.println("删除订单");
                        System.out.println("*****************************************************************************");
                        System.out.println("您要删除的订单是：");
                        int delete = (input.nextInt() - 1);
                        if (delete >= 0 && delete < 4) {
                            int k = 0 ;
                            for (int j = delete; j < 3; j++) {
                                if(name[j+1] != null  ){
                                name[j] = name[j + 1];
                                foodName[j] = foodName[j + 1];
                                foodQuantity[j] = foodQuantity[j + 1];
                                time[j] = time[j + 1];
                                address[j] = address[j + 1];
                                foodSum[j] = foodSum[j + 1];
                                condition[j] = condition[j + 1];
                                k = j+1;
                                }
                            }
                            if(delete == 3){
                                k = 3;
                            }
                            name[k] = null;
                            foodName[k] = null;
                            foodQuantity[k] = 0;
                            time[k] = null;
                            address[k] = null;
                            foodSum[k] = 0;
                            condition[k] = 0;

                            System.out.println("删除成功");
                        } else {
                            System.out.println("输入错误");
                        }

                        System.out.println("输入0返回上一菜单");
                        numberNo = input.nextInt();
                        if(numberNo != 999999999){
                            break;
                        }
                    case 5:
                        System.out.println("我要点赞");
                        System.out.println("*****************************************************************************");
                        System.out.println("菜品编码\t菜品名称\t\t点赞数");
                        for (int j = 0; j < 4; j++) {
                            System.out.println((j + 1) + "\t\t" + food[j] + "\t  " + like[j]);
                        }
                        System.out.println("请输入您要点赞的菜品编号：");
                        int likeId = input.nextInt();
                        switch (likeId) {
                            case 1:
                                like[0] = like[0] + 1;
                                break;
                            case 2:
                                like[1] = like[1] + 1;
                                break;
                            case 3:
                                like[2] = like[2] + 1;
                                break;
                            case 4:
                                like[3] = like[3] + 1;
                                break;
                            default:
                                break;
                        }
                        System.out.println("输入0返回上一菜单");
                        numberNo = input.nextInt();
                        if(numberNo != 999999999){
                            break;
                        }
                    default:
                }
            } else if (number == 6) {
                System.out.println("谢谢使用吃货联盟，欢迎下订餐！");
                break;

            } else {
                System.out.println("输入错误！请输入正确的数字！");
            }
        }

    }


}
